#include using namespace std; void getNumbers(int list[], int numbersToGet ) { for(int i = 0; i < numbersToGet;i++) { cin >> list[i]; } } void removeItemAtIndex(int list[], int index, int& length) { for(int i = index; i < length-1; i++) { list[i] = list[i+1]; } length--; } void displayNumbers(int list[], int length ) { for(int i = 0; i < length; i++) { cout << list[i] << endl; } } void insertItemAtIndex(int list[], int index, int n, int& gradeCount) { for(int i = gradeCount; i > index; i--) { list[i] = list[i - 1]; } list[index] = n; gradeCount++; } void selectionSort(int* list, int length, bool sortAscending) { for(int i = 0; i < length; i++) { int indexOfItemToMove = i; for(int j = i + 1; j < length; j++) { if(sortAscending) { if(list[j] < list[indexOfItemToMove]) { indexOfItemToMove = j; } } else { if(list[j] > list[indexOfItemToMove]) { indexOfItemToMove = j; } } } // swap item at index i with item at index of smallest int temp = list[i]; list[i] = list[indexOfItemToMove]; list[indexOfItemToMove] = temp; } } void bubbleSort(int list[], int length) { int timesLooped = 0; bool sorted = false; for(int i = 0; i < length-1 && !sorted; i++) { sorted = true; for(int j = 0; j < length - 1 - i; j++) { timesLooped++; if(list[j] > list[j+1]) { int temp = list[j]; list[j] = list[j+1]; list[j+1] = temp; sorted = false; } } } cout << "It looped " << timesLooped << " times\n"; } void reverseList(int list[], int length) { for(int i = 0; i < length/2; i++) { int temp = list[i]; list[i] = list[length - i - 1]; list[length - i - 1] = temp; } } void main() { int grades[312000]; int gradeCount; cout << "How many grades do you want to enter? "; cin >> gradeCount; cout << endl; getNumbers(grades, gradeCount); //removeItemAtIndex(grades, 2, gradeCount); //removeDuplicates cout << endl; cout << endl; cout << endl; //insertItemAtIndex(grades,20000,777,gradeCount); //selectionSort(grades,gradeCount, true); //reverseList(grades,gradeCount); bubbleSort(grades, gradeCount); displayNumbers(grades, gradeCount); //cout << grades; }